#!/usr/bin/env bash

# ----------------------------------------------------------------------
# Filename	:  01-setenforce-secadm.sh
# Version	:  1.0
# Date		:  2020/05/28
# Author	:  Lz
# Email		:  lz843723683@gmail.com
# History	:     
#                  Version 1.0, 2020/05/28
# Function	： 测试三权分立secadm-会话内开关安全
# Out		:        
#              0 => TPASS
#              1 => TFAIL
#              other=> TCONF
# ----------------------------------------------------------------------

# 测试主题
Title_Env_LTFLIB="三权分立(secadm) - 会话内开关安全"

HeadFile_Source_LTFLIB="${LIB_SSHAUTO}"

## TODO : 个性化,初始化
#   Out : 0=>TPASS
#         1=>TFAIL
#         2=>TCONF
TestInit_LTFLIB(){
	return ${TPASS}
}


## TODO : 清理函数
#   Out : 0=>TPASS
#         1=>TFAIL
#         2=>TCONF
TestClean_LTFLIB(){
	return ${TPASS}
}


## TODO ：用户标识Setenforce不一样
testcase_1(){
	local flag=""

	SshAuto_CmdLocalSec_LTFLIB "sudo setenforce 0" "no" "no"
	flag=$(getenforce)
	echo "getenforce = $flag"
	if [ "Z$flag" == "ZPermissive" ];then
		OutputRet_LTFLIB ${TPASS}
		TestRetParse_LTFLIB "要求getenforce = Permissive" "False"
	else
		OutputRet_LTFLIB ${TFAIL}
		TestRetParse_LTFLIB "要求getenforce = Permissive. 当前为 $flag" "False"
	fi
	
	SshAuto_CmdLocalSec_LTFLIB "sudo setenforce 1" "no" "no"
	flag=$(getenforce)
	echo "getenforce = $flag"
	if [ "Z$flag" == "ZEnforcing" ];then
		OutputRet_LTFLIB ${TPASS}
		TestRetParse_LTFLIB "要求getenforce = Enforcing" "False"
	else
		OutputRet_LTFLIB ${TFAIL}
		TestRetParse_LTFLIB "要求getenforce = Enforcing. 当前为 $flag" "False"
	fi
}

## TODO : 测试用例集
#   Out : 0=>TPASS
#         1=>TFAIL
#         2=>TCONF
Testsuite_LTFLIB(){
	testcase_1

	return $TPASS
}


#----------------------------------------------#

source "${LIB_LTFLIB}"
Main_LTFLIB $@
